package gorm

import (
	"fmt"
	"gin_api/core/configure"
	"gin_api/global"
)

// Init 初始化连接
func Init() {
	// 数据库连接
	db := DB{
		Driver:   "mysql",
		Host:     configure.GetString("gorm.mysql.host"),
		User:     configure.GetString("gorm.mysql.user"),
		Pass:     configure.GetString("gorm.mysql.pass"),
		Port:     configure.GetInt("gorm.mysql.port"),
		Database: configure.GetString("gorm.mysql.database"),
		Charset:  "utf8mb4",
	}
	err := db.Connect()
	if err != nil {
		fmt.Printf("Database connection failed，error：%v\n", err.Error())
		return
	}
	global.DB = db.Connection
}
